export function calCinradOption(val, option) {
  for (let j = 0; option[j] != null; j++) {
    if (option[j]['value'] === val) {
      return option[j]
    }
  }

  return null
}

export function calCinradCenter(val) {
  return [val['cx'], val['cy']]
}

export function number2size(val) {
  return val + 'px'
}

export function calCinradLevel2Option(val, option) {
  for (let i = 0; i < option.length; i++) {
    if (val[0] === option[i]['value']) {
      const _productArray = option[i]['children']

      for (let j = 0; j < _productArray.length; j++) {
        if (_productArray[j]['value'] === val[1]) {
          return _productArray[j]
        }
      }
    }
  }

  return {}
}

export function calCinradElevOption(val, option) {
  for (let i = 0; i < option.length; i++) {
    if (val[0] === option[i]['value']) {
      const _productArray = option[i]['children']

      for (let j = 0; j < _productArray.length; j++) {
        if (_productArray[j]['value'] === val[1]) {
          return _productArray[j]['children']
        }
      }
    }
  }

  return []
}

export function calElevLabel(val, productOption) {
  // console.debug(productOption)
  const _tmpOption = calCinradElevOption(val, productOption)
  // console.debug('calElevLabel')
  // console.debug(productOption)
  for (let j = 0; _tmpOption[j] != null; j++) {
    if (_tmpOption[j]['value'] === val[2]) {
      return _tmpOption[j]['label']
    }
  }

  return ''
}

export function compareArraysEqual(arr1, arr2) {
  if (arr1 == null && arr2 == null) {
    console.debug('compareArraysEqual Warn:arr1 == null &&  arr2 == null')
    return true
  }
  if (arr1 == null || arr2 == null) {
    console.error('compareArraysEqual Error:arr1 == null || arr2 == null')
    return false
  }

  if (arr1.length === 0 && arr2.length === 0) {
    console.debug(
      'compareArraysEqual Error:arr1.length === 0 && arr2.length === 0'
    )
    return true
  }

  if (arr1.length === 0 || arr2.length === 0) {
    console.debug(
      'compareArraysEqual Error:arr1.length === 0 || arr2.length === 0'
    )
    return false
  }

  if (arr1.length === arr2.length) {
    for (let i = 0; i < arr1.length; i++) {
      if (arr1[i] !== arr2[i]) {
        return false
      }
    }
    return true
  } else {
    return false
  }
}
